package io.gitee.dqcer.mcdull.uac.provider.web.car.service.impl;

import java.util.ArrayList;
import java.util.List;

import io.gitee.dqcer.mcdull.uac.provider.system.mapper.SysUserMapper;
import io.gitee.dqcer.mcdull.uac.provider.web.car.domain.CarPointsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import io.gitee.dqcer.mcdull.uac.provider.web.car.mapper.CarPointsMapper;
import io.gitee.dqcer.mcdull.uac.provider.web.car.domain.CarPoints;
import io.gitee.dqcer.mcdull.uac.provider.web.car.service.ICarPointsService;

import javax.annotation.Resource;

/**
 * 积分记录Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-12-10
 */
@Service
public class CarPointsServiceImpl implements ICarPointsService 
{
    @Autowired
    private CarPointsMapper carPointsMapper;

    @Resource
    private SysUserMapper sysUserMapper;

    /**
     * 查询积分记录
     * 
     * @param pointsId 积分记录主键
     * @return 积分记录
     */
    @Override
    public CarPoints selectCarPointsByPointsId(Long pointsId)
    {
        return carPointsMapper.selectCarPointsByPointsId(pointsId);
    }

    /**
     * 查询积分记录列表
     * 
     * @param carPoints 积分记录
     * @return 积分记录
     */
    @Override
    public List<CarPointsVO> selectCarPointsList(CarPoints carPoints)
    {
        List<CarPointsVO> list = new ArrayList<>();
        List<CarPoints> pointsList = carPointsMapper.selectCarPointsList(carPoints);
        for (CarPoints points : pointsList) {
            CarPointsVO vo = this.convertVO(points);
            vo.setNickName(sysUserMapper.selectUserById(vo.getUserId()).getNickName());
            list.add(vo);
        }
        return list;
    }

    private CarPointsVO convertVO(CarPoints points) {
        CarPointsVO carPointsVO = new CarPointsVO();
        carPointsVO.setPointsId(points.getPointsId());
        carPointsVO.setUserId(points.getUserId());
        carPointsVO.setTransactionType(points.getTransactionType());
        carPointsVO.setTransactionAmount(points.getTransactionAmount());
        carPointsVO.setPointsBalance(points.getPointsBalance());
        carPointsVO.setCreatedAt(points.getCreatedAt());
        carPointsVO.setUpdatedAt(points.getUpdatedAt());
        carPointsVO.setSearchValue(points.getSearchValue());
        carPointsVO.setCreateBy(points.getCreateBy());
        carPointsVO.setCreateTime(points.getCreateTime());
        carPointsVO.setUpdateBy(points.getUpdateBy());
        carPointsVO.setUpdateTime(points.getUpdateTime());
        carPointsVO.setRemark(points.getRemark());
        carPointsVO.setParams(points.getParams());
        return carPointsVO;
    }

    /**
     * 新增积分记录
     * 
     * @param carPoints 积分记录
     * @return 结果
     */
    @Override
    public int insertCarPoints(CarPoints carPoints)
    {
        return carPointsMapper.insertCarPoints(carPoints);
    }

    /**
     * 修改积分记录
     * 
     * @param carPoints 积分记录
     * @return 结果
     */
    @Override
    public int updateCarPoints(CarPoints carPoints)
    {
        return carPointsMapper.updateCarPoints(carPoints);
    }

    /**
     * 批量删除积分记录
     * 
     * @param pointsIds 需要删除的积分记录主键
     * @return 结果
     */
    @Override
    public int deleteCarPointsByPointsIds(Long[] pointsIds)
    {
        return carPointsMapper.deleteCarPointsByPointsIds(pointsIds);
    }

    /**
     * 删除积分记录信息
     * 
     * @param pointsId 积分记录主键
     * @return 结果
     */
    @Override
    public int deleteCarPointsByPointsId(Long pointsId)
    {
        return carPointsMapper.deleteCarPointsByPointsId(pointsId);
    }
}
